package com.zhudao.crawler;

import com.zhudao.crawler.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@SpringBootApplication
@EnableAsync
public class CrawlerApplication implements CommandLineRunner {

    @Bean
    public ThreadPoolTaskExecutor createThreadPoolTaskExecutor() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        threadPoolTaskExecutor.setCorePoolSize(10);
        threadPoolTaskExecutor.setMaxPoolSize(20);
        return threadPoolTaskExecutor;
    }

    public static void main(String[] args) {
        SpringApplication.run(CrawlerApplication.class, args);
    }

    @Autowired
    AnjukeService anjukeService;
    @Autowired
    PinyinService pinyinService;
    @Autowired
    CrawlerFangTianXiaService crawlerFangTianXiaService;
    @Autowired
    CrawlerDoubanService crawlerDoubanService;
    @Autowired
    CrawlerGangJiService crawlerGangJiService;


    @Override
    public void run(String... strings) throws Exception {
        //anjukeService.runAnjukeCommuity();
        // pinyinService.communityUpdate();
        //crawlerDoubanService.douban();
        crawlerGangJiService.gangji("经纪人合租", "https://fangapi.ganji.com/api/v1/fang/v1/post/houselist/?callback=jsonp2&validListType=12,1,4&domain=sh&url=fang3&agent=3&zufang=3&page=1&share_mode=1&uri=&a=pl&d=&subway=false&category=fang3&city_domain=sh&type=extend&page_no=");
        Thread.sleep(2000);
        crawlerGangJiService.gangji("经纪人整租", "https://fangapi.ganji.com/api/v1/fang/v1/post/houselist/?callback=jsonp2&validListType=12,4&domain=sh&url=fang1&agent=1&zufang=1&page=1&uri=a1m1%2F&a=pl&d=a1m1%2F&subway=false&category=fang1&city_domain=sh&type=extend&page_no=");
        Thread.sleep(2000);
        crawlerGangJiService.gangji("房东", " https://fangapi.ganji.com/api/v1/fang/v1/post/houselist/?callback=jsonp6&validListType=12,1,4&domain=sh&url=fang1&zufang=1&page=1&uri=m1%2F&a=pl&d=m1%2F&subway=false&category=fang1&city_domain=sh&type=extend&page_no=");
        //  crawlerFangTianXiaService.fangtianxia(".sh.", "上海");
//        crawlerFangTianXiaService.fangtianxia(".", "北京");
//        crawlerFangTianXiaService.fangtianxia(".gz.", "广州");
//        crawlerFangTianXiaService.fangtianxia(".sz.", "深圳");
//        crawlerFangTianXiaService.fangtianxia(".cd.", "成都");
//        crawlerFangTianXiaService.fangtianxia(".zz.", "郑州");
//        crawlerFangTianXiaService.fangtianxia(".cs.", "长沙");
//        crawlerFangTianXiaService.fangtianxia(".nj.", "南京");
//        crawlerFangTianXiaService.fangtianxia(".cq.", "重庆");
//        crawlerFangTianXiaService.fangtianxia(".suzhou.", "苏州");
//        crawlerFangTianXiaService.fangtianxia(".wz.", "温州");
//        crawlerFangTianXiaService.fangtianxia(".hz.", "杭州");
//        crawlerFangTianXiaService.fangtianxia(".hf.", "合肥");
//        crawlerFangTianXiaService.fangtianxia(".xian.", "西安");
//        crawlerFangTianXiaService.fangtianxia(".dg.", "东莞");
//        crawlerFangTianXiaService.fangtianxia(".jn.", "济南");
//        crawlerFangTianXiaService.fangtianxia(".qd.", "青岛");
//        crawlerFangTianXiaService.fangtianxia(".sjz.", "石家庄");
//        crawlerFangTianXiaService.fangtianxia(".wuxi.", "无锡");
//        crawlerFangTianXiaService.fangtianxia(".nc.", "南昌");
//        crawlerFangTianXiaService.fangtianxia(".km.", "昆明");
//        crawlerFangTianXiaService.fangtianxia(".changchun.", "长春");
//        crawlerFangTianXiaService.fangtianxia(".dl.", "大连");
//        crawlerFangTianXiaService.fangtianxia(".fz.", "福州");
//        crawlerFangTianXiaService.fangtianxia(".zh.", "珠海");
//        crawlerFangTianXiaService.fangtianxia(".nn.", "南宁");
        //anjukeService.runAnjukeCommuity();
    }


}
